package com.ruoyi.work.service.impl;

import java.util.*;
import java.util.stream.Collectors;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.resumes.mapper.ResumesMapper;
import com.ruoyi.system.mapper.ApplicationsMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.work.mapper.JobbasicinfoMapper;
import com.ruoyi.work.domain.Jobbasicinfo;
import com.ruoyi.work.service.IJobbasicinfoService;

/**
 * 岗位job管理Service业务层处理
 *
 * @author ruoyi
 * @date 2024-11-10
 */
@Service
public class JobbasicinfoServiceImpl implements IJobbasicinfoService
{
    @Autowired
    private JobbasicinfoMapper jobbasicinfoMapper;
    @Autowired
    private ApplicationsMapper applicationsMapper;
    @Autowired
    private ResumesMapper resumesMapper;

    /**
     * 查询岗位job管理
     *
     * @param jobId 岗位job管理主键
     * @return 岗位job管理
     */
    @Override
    public Jobbasicinfo selectJobbasicinfoByJobId(Long jobId)
    {
        return jobbasicinfoMapper.selectJobbasicinfoByJobId(jobId);
    }

    @Override
    public Jobbasicinfo selectJobIdByJobNameandcompanyname(String jobtitle,String companyname) {
        return jobbasicinfoMapper.selectJobIdByJobNameandcompanyname(jobtitle,companyname);
    }

    /**
     * 查询岗位job管理列表
     *
     * @param jobbasicinfo 岗位job管理
     * @return 岗位job管理
     */
    @Override
    public List<Jobbasicinfo> selectJobbasicinfoList(Jobbasicinfo jobbasicinfo)
    {
        return jobbasicinfoMapper.selectJobbasicinfoList(jobbasicinfo);
    }

    /**
     * 新增岗位job管理
     *
     * @param jobbasicinfo 岗位job管理
     * @return 结果
     */
    @Override
    public int insertJobbasicinfo(Jobbasicinfo jobbasicinfo)
    {
        return jobbasicinfoMapper.insertJobbasicinfo(jobbasicinfo);
    }

    /**
     * 修改岗位job管理
     *
     * @param jobbasicinfo 岗位job管理
     * @return 结果
     */
    @Override
    public int updateJobbasicinfo(Jobbasicinfo jobbasicinfo)
    {
        return jobbasicinfoMapper.updateJobbasicinfo(jobbasicinfo);
    }

    /**
     * 批量删除岗位job管理
     *
     * @param jobIds 需要删除的岗位job管理主键
     * @return 结果
     */
    @Override
    public int deleteJobbasicinfoByJobIds(Long[] jobIds)
    {
        return jobbasicinfoMapper.deleteJobbasicinfoByJobIds(jobIds);
    }

    /**
     * 删除岗位job管理信息
     *
     * @param jobId 岗位job管理主键
     * @return 结果
     */
    @Override
    public int deleteJobbasicinfoByJobId(Long jobId)
    {
        return jobbasicinfoMapper.deleteJobbasicinfoByJobId(jobId);
    }

    /**
     * 查询收藏列表
     * @param jobbasicinfo
     * @return
     */
    @Override
    public List<Jobbasicinfo> selectCollections(Jobbasicinfo jobbasicinfo) {
        //获取当前用户id
        Long userId= SecurityUtils.getUserId();
        //获取role_id
        List roleId=resumesMapper.getRoleId(userId);
        //判断是否是应聘者
        if(roleId.contains(100)){
            //根据用户id查询
            List<Jobbasicinfo> list1= jobbasicinfoMapper.selectJobbasicinfoByUserId(userId);
            //根据搜索框查询
            List<Jobbasicinfo> list2=jobbasicinfoMapper.selectJobbasicinfoList(jobbasicinfo);
            //两个集合取交集
            Set<Jobbasicinfo> set=new HashSet<>(list1);
            List<Jobbasicinfo> list=new ArrayList<>();
            for(Jobbasicinfo jobbasicinfo1:list2){
                if(set.contains(jobbasicinfo1)){
                    list.add(jobbasicinfo1);
                }
            }
            return list;
        }
        List<Jobbasicinfo> list=new ArrayList<>();
        /*List<Jobbasicinfo> list=jobbasicinfoMapper.selectJobbasicinfoList(jobbasicinfo);*/
        return list;
    }


}
